home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_htmllib.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  1.1 KB  |  43 lines

  1. import formatter
  2. import htmllib
  3. import unittest
  4.  
  5. import test_support
  6.  
  7.  
  8. class AnchorCollector(htmllib.HTMLParser):
  9.     def __init__(self, *args, **kw):
  10.         self.__anchors = []
  11.         htmllib.HTMLParser.__init__(self, *args, **kw)
  12.  
  13.     def get_anchor_info(self):
  14.         return self.__anchors
  15.  
  16.     def anchor_bgn(self, *args):
  17.         self.__anchors.append(args)
  18.  
  19.  
  20. class HTMLParserTestCase(unittest.TestCase):
  21.     def test_anchor_collection(self):
  22.         # See SF bug #467059.
  23.         parser = AnchorCollector(formatter.NullFormatter(), verbose=1)
  24.         parser.feed(
  25.             """<a href='http://foo.org/' name='splat'> </a>
  26.             <a href='http://www.python.org/'> </a>
  27.             <a name='frob'> </a>
  28.             """)
  29.         parser.close()
  30.         self.assertEquals(parser.get_anchor_info(),
  31.                           [('http://foo.org/', 'splat', ''),
  32.                            ('http://www.python.org/', '', ''),
  33.                            ('', 'frob', ''),
  34.                            ])
  35.  
  36.  
  37. def test_main():
  38.     test_support.run_unittest(HTMLParserTestCase)
  39.  
  40.  
  41. if __name__ == "__main__":
  42.     test_main()
  43.